import tkinter
import tkmacosx
import requests


def get_chatlog(username,friendname):
    ses = requests.Session()
    dict = {"username": username, "friendname": friendname}
    url = "http://127.0.0.1:4000/chatlog"
    res = ses.post(url, dict).text
    res = eval(res)
    return res


def create_show_chat(username, friendname):
    res = get_chatlog(username, friendname)
    yun = tkinter.Toplevel()
    frame = tkmacosx.SFrame(yun, width=600, height=800)
    text = tkinter.Text(frame, height=80, width=650)
    text.grid(row=0, column=0)
    text.tag_config("tag1", foreground="green", font=("", 18))
    text.tag_config("tag2", foreground="black", font=("", 20))
    for i in res:
        print(i)
        text.insert("end",i[2]+"\n",'tag1')
        text.insert("end",i[0]+":"+i[1]+"\n",'tag2')
    text.config(state="disable")
    frame.pack()
    yun.title("聊天记录")
    yun.mainloop()


if __name__ == '__main__':
    create_show_chat("15133854715","17849327316")
    # path = "/Users/sapple/Documents/python_webchat/serverer/1.png"
    # main(path)

